﻿namespace Arms.Persistence.Base.Conventions
{
    using Arms.Domain;
    using System;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity.ModelConfiguration.Conventions;

    public class EntityNamingConvention : Convention
    {
        public EntityNamingConvention()
        {
            this.Types<Entity>().Configure(x =>
            {
                x.Property(p => p.ID).HasColumnName(x.ClrType.Name + "ID").IsKey().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnOrder(1);
                x.Property(p => p.ActiveState).IsRequired();
            });

            this.Types<EntityDescribed>().Configure(x =>
            {
                x.Property(p => p.Name).IsRequired().HasColumnName(x.ClrType.Name + "Name").IsMaxLength().HasColumnOrder(2);
                x.Property(p => p.Description).HasColumnName(x.ClrType.Name + "Description").IsMaxLength().HasColumnOrder(3);
                x.Property(p => p.Comment).HasColumnName(x.ClrType.Name + "Comment").IsMaxLength().HasColumnOrder(4);
            });
        }
    }
}
